package com.unnison.demo.client.login;

import com.google.inject.Inject;

import com.unnison.demo.client.login.LoginPresenter;
import com.unnison.demo.client.login.LoginPresenter.LoginBinder;
import com.unnison.demo.client.main.MainPresenter;
import com.unnison.framework.junit.GuitTest;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

public class TestLoginPresenter extends GuitTest {

    @Inject
    LoginPresenter presenter;

    @Override
    protected void configure() {
        mock(LoginBinder.class);
        mock(MainPresenter.class);
    }

    @Before
    public void setUp() {
        presenter.go(null);
    }

    @Test
    public void testClear() {
        presenter.clear$click();
        Assert.assertNull(presenter.username.getText());
        Assert.assertNull(presenter.password.getText());
        Assert.assertNull(presenter.message.getInnerText());
    }

    @Test
    public void testFailureKeyPress() {
        presenter.username.setText("bad");
        presenter.password.setText("guy");
        presenter.login$username$password$keyPress();
        Assert.assertEquals(LoginPresenter.ERROR_LOGGIN_IN, presenter.message.getInnerText());
    }

    @Test
    public void testFailureLogin() {
        presenter.username.setText("bad");
        presenter.password.setText("guy");
        presenter.login$click();
        Assert.assertEquals(LoginPresenter.ERROR_LOGGIN_IN, presenter.message.getInnerText());
    }

    @Test
    public void testSuccessKeyPress() {
        presenter.username.setText("admin");
        presenter.password.setText("admin");
        presenter.login$username$password$keyPress();
        Assert.assertEquals(LoginPresenter.YOU_LOGGED_IN, presenter.message.getInnerText());
    }

    @Test
    public void testSuccessLogin() {
        presenter.username.setText("admin");
        presenter.password.setText("admin");
        presenter.login$click();
        Assert.assertEquals(LoginPresenter.YOU_LOGGED_IN, presenter.message.getInnerText());
    }
}
